package com.eairlv.route.client.interceptor;

import com.eairlv.route.client.entity.RouteForm;
import com.eairlv.route.client.entity.RouteHandlerForm;
import com.eairlv.route.client.utils.BeanUtil;
import feign.Target;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;

/**
 * @author eairlv
 * @description
 * @date 18:09 2019/12/12
 */
@Slf4j
public class SimpleRouteInterceptor implements RouteInterceptor {

    @Override
    public String applyKey(Object key, Integer type, Method method, Object[] args, Target target) {
        return key.toString();
    }

    @Override
    public Integer applyType(Object key, Integer type, Method method, Object[] args, Target target) {
        return type;
    }

    @Override
    public RouteForm applyRoute(RouteHandlerForm routeHandlerForm, Method method, Object[] args, Target target) {
        RouteForm routeForm = BeanUtil.copyProperties(routeHandlerForm, RouteForm.class);
        routeForm.setKey(routeHandlerForm.toString());
        return routeForm;
    }
}
